package com.afalon.cloud.contracts.finance;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
	
	// Types of Account
	
	// Asset - Debit
	// Expense - Debit
	// Liability - Credit
	// Income - Credit
	
	// Debit Transaction increases Asset & Expense, decreases Liability and Income
	// Credit Transaction increases Liability & Income, decreases Asset and Expense
	
	/*

	Get Paid
	Employer	Income(Credit)		Credited	Increased		1000
	Current		Asset(Debit)		Debited		Increased		1000
	
	Get Paid Full Split
	Employer	Income(Credit)		Credited	Increased		2501.99
	Current		Asset(Debit)		Debited		Increased		1766.17
	NatIns		Expense(Debit)		Debited		Increased		228.00
	IncomeTax	Expense(Debit)		Debited		Increased		370.80
	StudentLoan	Liability(Credit)	Debited		Decreased		112.00
	Pension		Asset(Debit)		Debited		Increased		25.02
	
	Buy Book with Debit Card
	Current		Asset(Debit)		Credited	Decreased		10
	Assets		Asset(Debit)		Debited		Increased		10
	
	Buy DVD with Credit Card
	CreditCard	Liability(Credit)	Credited	Increased		15
	Assets		Asset(Debit)		Debited		Increased		15
	
	Pay Gas Bill
	Current		Asset(Debit)		Credited	Decrease		30
	GasCo		Expense(Debit)		Debited		Increases		30
	
	Pay Credit Card Bill
	Current		Asset(Debit)		Credited	Decreased		50
	CreditCard	Liability(Credit)	Debited		Decreased		50
	
	Get Loan
	Loan		Liability(Credit)	Credited	Increased		10000
	Current		Asset(Debit)		Debited		Increased		10000

	 */

@PersistenceCapable
@XmlRootElement(name = "account")
@XmlAccessorType(XmlAccessType.NONE)
public class Account 
{
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key accountKey;
	
	/* @Ref(resource=Chart.class) */
	@XmlElement
	private String chartUri;
	
	@XmlElement
	@Persistent
	private String name;
	
	@XmlElement
	@Persistent
	private String type;
	// (D)ebit, (C)redit

	@XmlElement
	@Persistent
	private String group;
	// (A)sset, (L)iability, (I)ncome, (E)xpense
	
	@Persistent
	private Chart chart;
	
	@Persistent(mappedBy = "account")
    private List<TransactionLine> transactionLines;
	
	public Account() 
	{
		
	}
	
	public Key getAccountKey() {
		return accountKey;
	}

	
	/* @XmlElement */
	public String getAccountId() {
		return KeyFactory.keyToString(this.getAccountKey());
	}
	

	public String getChartUri() {
		
		return chartUri;
	}
	
	public void setName(String value) {
		name = value;
	}

	public String getName() {
		return name;
	}
	
	public void setType(String value) {
		type = value;
	}

	public String getType() {
		return type;
	}
	
	public void setGroup(String value) {
		group = value;
	}

	public String getGroup() {
		return group;
	}

	public List<TransactionLine> getTransactionLines() {
		return transactionLines;
	}
	
	// Foreign Fields
	
	// Parent Id
	
	/*
	@XmlElement
	public String getChartId() {
		return chart.getChartId();
	}
	*/
	
}
